package com.ruan.service;

import com.ruan.dao.AddressMapper;
import com.ruan.dao.UserAddressMapper;
import com.ruan.entity.Address;
import com.ruan.entity.Result;
import com.ruan.entity.UserAddress;
import com.ruan.vo.AddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName:AddressService
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/7/3 10:12
 **/
@Service
public class AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Transactional
    public Result addAddress(AddressVo addressVo) {
        int row1 = addressMapper.addAddress(addressVo);
        addressVo.setAddressId(addressMapper.getLastId());
        int row2 = userAddressMapper.addAddress(addressVo);
        if(row1 != row2){
            return new Result(100,"地址添加失败");
        }else {
            return new Result(200,"地址添加成功");
        }
    }
}
